Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
12-Jun-2025How Routing Works in ASP.NET MVC
Routing in ASP.NET MVC maps incoming URL requests to controller actions. It decouples the URL structure from the physical file paths, allowing clean, user-friendly URLs.
1. Conventional Routing
Defined in
RouteConfig.cs(usually inApp_Startfolder):Example URL Matching:
/Home/Index/Product/Details/52. Attribute Routing
Instead of defining routes globally, you place route attributes directly on controllers and actions.
Enable it (usually in
RouteConfig.cs):Example: Using Attribute Routing
This maps:
/products/list→ProductsController.List()/products/details/10→ProductsController.Details(10)Advanced Attribute Routing
Optional Parameters
Matches
/blog/2025and/blog/2025/06Route Names and Constraints
idis an integer ≥ 1Url.RouteUrl("OrderDetails", new { id = 5 })to generate the URLSummary: Conventional vs Attribute Routing
When to Use Attribute Routing